(setq custom-safe-themes t)

;;(global-display-line-numbers-mode 1)
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

(setq-default mode-line-format
      (list
       '(:eval  (if (eq evil-state 'insert)
		     (propertize "-- INSERT --" 'face '(:foreground "#2a2a2a" :background "#bde0b1"))
		  (if (eq evil-state 'normal)
		      (propertize "-- NORMAL --" 'face '(:foreground "#2a2a2a" :background "#f5aca4"))
		    (if (eq evil-state 'visual)
			(propertize "-- VISUAL --" 'face '(:foreground "#2a2a2a" :background "#ffda40"))
		    ))))
			    
      
       (propertize "        %b        "
		    'face '(:foreground "#2a2a2a" :background "#dfcfeb"))
    
       (propertize "        %f        "
		    'face '(:foreground "#2a2a2a" :background "#bedbf0"))
       ))

(fringe-mode '(4 . 4))
(setq inhibit-compacting-font-caches t)
(setq find-file-visit-truename t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq-default visible-bell t)
(setq initial-scratch-message ";;That functional.\n;;That libre.\n;;That bloat...\n\n\n")
(setq use-file-dialog nil)
(setq use-dialog-box nil)
(setq-default buffer-file-coding-system 'utf-8-unix)
(set-terminal-coding-system 'utf-8)
(setq split-height-threshold nil split-width-threshold nil)
(set-language-environment 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(setq show-paren-delay 0)
(setq show-paren-style 'parenthesis)
(show-paren-mode)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)))
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
(setq org-image-actual-width (/ (display-pixel-width) 10))


(setq inhibit-splash-screen t)
(set-default-font "Iosevka 14")

;;(load-file "~/shoji-niji-theme.el")
;;; Use-package init
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
;;(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(require 'use-package-ensure)
(setq use-package-always-ensure t)

;;; Custom packages
;;(add-to-list 'eshell-modules-list 'eshell-tramp)
(use-package writeroom-mode)

(use-package haskell-mode
  :config
  (defun hlint ()
  (interactive)
  (shell-command "hlint ."))
  
  (setq haskell-process-type 'ghci)
  (add-hook 'haskell-mode-hook (lambda ()
				 (interactive)
				 (local-set-key (kbd "M-q") 'hlint)
				 (interactive-haskell-mode)))
  )




(use-package nix-mode)

(use-package rainbow-mode)

(use-package yasnippet
  :init
  (yas-global-mode 1)
  :config
  (setq yas-triggers-in-field t)
  (setq yas-next-field-or-maybe-expand t)
  (setq yas-snippet-dirs
	'("~/.emacs.d/snippets")))

;;(use-package nyan-mode :config (nyan-mode) (nyan-start-animation) (nyan-toggle-wavy-trail))

(use-package spacemacs-theme
  :defer t
  :init
  ;;(load-theme 'spacemacs-light t)
  )

(use-package multiple-cursors
  :config
  (global-set-key (kbd "C->") 'mc/mark-next-like-this)
  (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
  (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this))

(use-package rainbow-delimiters
  :init
  (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))

(use-package which-key
  :init
  (which-key-mode)
  :config
  (setq which-key-idle-delay 0.05)
  (setq which-key-idle-secondary-delay 0.05))

(use-package company
  :init
  (setq company-global-modes '(not eshell-mode))
  (add-hook 'after-init-hook 'global-company-mode)
  :config
  (setq company-dabbrev-other-buffers t)
  (setq company-dabbrev-code-other-buffers t)
  (setq company-idle-delay 0)
  (setq company-minimum-prefix-length 1)
  (setq company-selection-wrap-around t)

  (define-key company-active-map (kbd "S-SPC") 'company-select-next)
  (define-key company-active-map (kbd "C-SPC") 'company-select-previous)
  (define-key company-search-map (kbd "S-SPC") 'company-select-next)
  (define-key company-search-map (kbd "C-SPC") 'company-select-previous)

  )

(use-package company-ghci
  :init (push 'company-ghci company-backends))

(use-package org
  :config
  
  (setq org-image-actual-width nil)
  (setq
   header-line-format " "
   org-startup-indented t
   org-export-with-toc nil
   org-ellipsis " ↹ " 
   org-pretty-entities t
   org-startup-with-inline-images t
   org-latex-toggle-fragment t
   org-image-toggle-inline t
   org-hide-emphasis-markers t
   org-startup-with-latex-preview t
   org-agenda-block-separator ""
   org-fontify-whole-heading-line t
   org-fontify-done-headline t
   org-fontify-quote-and-verse-blocks t)
  (setq org-latex-default-packages-alist
	(quote
	 (("AUTO" "inputenc" t
	   ("pdflatex"))
	  ("T2A" "fontenc" t
	   ("pdflatex"))
	  ("" "graphicx" t nil)
	  ("" "grffile" t nil)
	  ("" "longtable" nil nil)
	  ("" "wrapfig" nil nil)
	  ("" "rotating" nil nil)
	  ("" "normalem" "ulem" t nil)
	  ("" "amsmath" t nil)
	  ("" "textcomp" t nil)
	  ("" "amssymb" t nil)
	  ("" "capt-of" nil nil)
	  ("" "hyperref" nil nil)
	  ("" "dsfont" nil nil)
	  ("russian,english" "babel" nil nil))))
  
  )

(use-package counsel
  :after ivy
  :config (counsel-mode))
(use-package counsel-tramp
  :after counsel
  :config
  (setq tramp-default-method "su")
  (define-key global-map (kbd "C-c s") 'counsel-tramp))
(use-package ivy
  :defer 0.1
  :bind (("C-c C-r" . ivy-resume)
	 ("C-x B" . ivy-switch-buffer-other-window))
  :custom
  (ivy-count-format "(%d/%d) ")
  (ivy-use-virtual-buffers t)
  :config (ivy-mode))

(use-package swiper
  :after ivy
  :bind (("C-s" . swiper)
	 ("C-r" . swiper)))

(use-package org-bullets
  :config
  (setq org-bullets-bullet-list '(" "))
  (visual-line-mode)
  (setq left-margin-width 5)
  (company-mode 0)
  
  (setq right-margin-width 5)
  (set-window-buffer nil (current-buffer))
  (setq org-format-latex-options
	'(:foreground "#2a2a2a" :background default :scale 2.5 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers ("begin" "$1" "$" "$$" "\\(" "\\[")))
  
  ;;'("◉" "○" "⊕" "⊝" "⍟" "⊜" "⊗"))
  :init
  
  (add-hook 'org-mode-hook (lambda ()
			     (interactive)
			     (with-eval-after-load 'ox-latex
			     (add-to-list 'org-latex-classes

					'("cheat"
					  
					  "\\documentclass[6pt,a4paper,twocolumn]{article}"                 					
					  ("\\section{%s}" . "\\section*{%s}")
					  ("\\subsection{%s}" . "\\subsection*{%s}")
					  ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
					  ("\\paragraph{%s}" . "\\paragraph*{%s}")
					  ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
			     
			     (org-bullets-mode 1)
			     )))
(set-input-method "belarusian")
(toggle-input-method)
(use-package key-chord
  :init
  (key-chord-mode 1))

(use-package speed-type
  :config
  (defun typing ()
    (interactive)
    (speed-type-text)))

(use-package evil
  :config
  ;;(setq evil-insert-state-cursor '(box "gray"))
  (setcdr evil-insert-state-map nil)
  (define-key evil-insert-state-map [escape] (kbd "C-g"))
  (define-key key-translation-map (kbd "<M-f1>") (kbd "—"))
  (key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
  (setq evil-default-state 'insert)
  
  :init
  (evil-mode)
  )

(deftheme shoji-niji
  "Shoji Niji theme")


(defun truecolor-or-graphic-p ()
  "Returns whether the display can display nord colors"
  (or (= (display-color-cells) 16777216) (display-graphic-p)))

(let
    ((class '((class color) (min-colors 89)))
      ;;Shoji palette
     (white   (if (truecolor-or-graphic-p) "#fefefe" "white"))
     (black   (if (truecolor-or-graphic-p) "#2a2a2a" "black"))
     (grey    (if (truecolor-or-graphic-p) "#e4e4e4" "grey"))
     (red     (if (truecolor-or-graphic-p) "#f5aca4" "red"))
     (orange  (if (truecolor-or-graphic-p) "#fac8a8" "orange"))
     (yellow  (if (truecolor-or-graphic-p) "#ffda40" "yellow"))
     (green   (if (truecolor-or-graphic-p) "#bde0b1" "green"))
     (aqua    (if (truecolor-or-graphic-p) "#bee6de" "blue"))
     (blue    (if (truecolor-or-graphic-p) "#bedbf0" "blue"))
     (purple  (if (truecolor-or-graphic-p) "#dfcfeb" "purple"))
     (pink    (if (truecolor-or-graphic-p) "#facfd4" "pink"))
     )
  (custom-theme-set-faces 
   'shoji-niji
   ;; Base
   `(default ((,class (:foreground ,black :background ,white))))
   `(error   ((,class (:foreground ,black :background ,red))))
   `(warning ((,class (:foreground ,black :background ,red))))
   `(fringe ((,class (:foreground ,black :background ,white))))
   `(escape-glyph ((,class (:foreground ,black :foreground ,purple))))
   `(match ((,class :foreground ,black :background ,yellow)))
   `(highlight ((,class :foreground ,black :background ,yellow)))
   `(isearch ((,class :foreground ,black :background ,yellow)))
   `(lazy-highlight ((,class :foreground ,black :background ,yellow)))
   `(show-paren-match ((,class :foreground ,black :background ,yellow)))
   `(show-paren-match-expression ((,class :foreground ,black :background ,yellow)))
   `(show-paren-mismatch ((,class :foreground ,black :background ,red)))
   `(mode-line ((,class (:foreground ,white :background ,blue))))
   `(mode-line-inactive ((,class (:foreground ,black :background ,grey))))
   `(minibuffer-prompt ((,class (:foreground ,black :background ,white :weight bold))))
   ;;Ivy
   `(ivy-current-match ((,class (:foreground ,white :background ,black))))
   `(ivy-minibuffer-match-face-1 ((,class (:inherit default))))
   `(ivy-minibuffer-match-face-1 ((,class (:foreground ,black :background ,yellow))))
   `(ivy-minibuffer-match-face-2 ((,class (:foreground ,black :background ,yellow))))
   `(ivy-minibuffer-match-face-3 ((,class (:foreground ,black :background ,yellow))))
   `(ivy-minibuffer-match-face-4 ((,class (:foreground ,black :background ,yellow))))
   ;;Font lock
   `(font-lock-regexp-grouping-backslash ((,class (:foreground ,black :background ,purple))))
   `(font-lock-warning-face ((,class (:foreground ,black :background ,red))))
   `(region ((,class (:foreground ,black :background ,yellow))))
   `(font-lock-builtin-face ((,class (:foreground ,black :background ,blue))))
   `(font-lock-constant-face ((,class (:foreground ,black :background ,blue))))
   `(font-lock-string-face ((,class :foreground ,black :background ,blue)))
   `(font-lock-type-face ((,class (:foreground ,black :background ,aqua))))
   `(font-lock-comment-delimiter-face ((,class :foreground ,black :background ,grey)))
   `(font-lock-comment-face ((,class :foreground ,black :background ,grey)))
   `(font-lock-keyword-face ((,class :foreground ,black :background ,green)))
   `(font-lock-function-face ((,class :foreground ,black :background ,pink)))
   `(font-lock-function-name-face ((,class :foreground ,black :background ,pink)))
   `(font-lock-variable-face ((,class :foreground ,black :background ,pink)))
   `(font-lock-variable-name-face ((,class :foreground ,black :background ,pink)))
   `(font-lock-preprocessor-face ((,class :foreground ,black :background ,orange)))
   `(font-lock-regexp-grouping-construct ((,class (:foreground ,black :background ,yellow))))
   ;;Rainbow
    `(rainbow-delimiters-depth-1-face ((,class :foreground ,black :background ,purple)))
    `(rainbow-delimiters-depth-2-face ((,class :inherit rainbow-delimiters-depth-1-face)))
    `(rainbow-delimiters-depth-3-face ((,class :inherit rainbow-delimiters-depth-1-face)))
    `(rainbow-delimiters-depth-4-face ((,class :inherit rainbow-delimiters-depth-1-face)))
    `(rainbow-delimiters-depth-5-face ((,class :inherit rainbow-delimiters-depth-1-face)))
    `(rainbow-delimiters-depth-6-face ((,class :inherit rainbow-delimiters-depth-1-face)))
    `(rainbow-delimiters-depth-7-face ((,class :inherit rainbow-delimiters-depth-1-face)))
    `(rainbow-delimiters-depth-8-face ((,class :inherit rainbow-delimiters-depth-1-face)))
    `(rainbow-delimiters-unmatched-face ((,class :inherit show-paren-mismatch)))
   ;;Company
   `(company-echo-common    ((,class (:foreground ,black :background ,grey))))
   `(company-preview        ((,class (:foreground ,black :background ,yellow))))
   `(company-preview-common ((,class (:foreground ,black :background ,yellow))))
   `(company-preview-search ((,class (:foreground ,black :background ,grey))))
   `(company-template-field ((,class (:foreground ,black :background ,grey))))
   `(company-scrollbar-bg   ((,class (:foreground ,grey  :background ,grey))))
   `(company-scrollbar-fg   ((,class (:foreground ,grey  :background ,grey))))
   `(company-tooltip        ((,class (:foreground ,black :background ,grey))))
   `(company-tooltip-annotation ((,class (:foreground ,black))))
   `(company-tooltip-annotation-selection ((,class (:foreground ,blue))))
   `(company-tooltip-common ((,class (:foreground ,black :background ,grey))))
   `(company-tooltip-common-selection ((,class (:foreground ,black :background ,yellow))))
   `(company-tooltip-mouse ((,class (:inherit default))))
   `(company-tooltip-selection ((,class (:foreground ,black :background ,yellow))))
   ;; Etc
   `(speed-type-correct ((,class (:foreground ,black :background ,green))))
   `(speed-type-mistake ((,class (:foreground ,black :background ,red))))
   ;;Terminal
   `(term ((,class (:foreground ,black :background ,white))))
   `(term-color-black ((,class (:foreground ,black :background ,black))))
   `(term-color-white ((,class (:foreground ,white :background ,white))))
   `(term-color-cyan ((,class (:foreground ,aqua :background ,aqua))))
   `(term-color-blue ((,class (:foreground ,blue :background ,blue))))
   `(term-color-red ((,class (:foreground ,red :background ,red))))
   `(term-color-yellow ((,class (:foreground ,yellow :background ,yellow))))
   `(term-color-green ((,class (:foreground ,green :background ,green))))
   `(term-color-magenta ((,class (:foreground ,purple :background ,purple))))
   `(eshell-prompt ((,class (:foreground ,black :background ,yellow))))
   `(eshell-ls-executable ((,class :foreground ,black :background ,green)))
   `(eshell-ls-directory ((,class :foreground ,black :background ,blue)))
   `(eshell-ls-backup ((,class :foreground ,black :background ,red)))
   ))
